import ReactDOM from 'react-dom';
/**
 * @method Micro 子应用统一封装、接收主应用数据的方法
 * @param setGlobalState 主应用暴露给子应用的方法setGlobalState,子应用要调用主应用的方法，通过此方法进行调用
 */
class Micro {
  constructor() {
    this.instanceContainer = null;
    this.render = function() {};
    this.setGlobalState = function() {};
  }
  setStore(props) {
    this.setGlobalState = props.setGlobalState;
  }
  bootstrap() {
    console.log('[react] react app bootstraped');
  }
  mount(props) {
    console.log('[react] props from main framework', props);
    this.setStore(props);
    this.render(props);
  }
  unmount() {
    ReactDOM.unmountComponentAtNode(this.instanceContainer);
    this.instanceContainer = null;
  }
}

const micro = new Micro();
export default micro;
